/*
 * @FilePath: \undefinedc:\Users\sxjct\.leetcode\83.删除排序链表中的重复元素.cpp
 * @Brief: 
 * @Version: 1.0
 * @Date: 2021-03-03 14:20:59
 * @Author: tianyiyi
 * @Copyright: Copyright@tianyiyi
 * @LastEditors: Mr.Tian
 * @LastEditTime: 2021-03-26 10:37:09
 */
/*
 * @lc app=leetcode.cn id=83 lang=cpp
 *
 * [83] 删除排序链表中的重复元素
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
/*
    ListNode* deleteDuplicates(ListNode* head,unordered_map<int,int> &list)
    {
        if(head == NULL)
            return head;
        ListNode* last = head->next;
        if(list[head->val] == 1)
        {
            //删除该节点
            return deleteDuplicates(last,list);
        }
        else
        {
            list[head->val]++;
            head->next = deleteDuplicates(last,list);
            return head;
        }
    }
    ListNode* deleteDuplicates(ListNode* head) {
        unordered_map<int,int> list;
        return deleteDuplicates(head,list);
    }
*/  
    // ListNode* deleteDuplicates(ListNode* head) {
    //     if(head == NULL ||head->next == NULL)
    //         return head;
    //     head->next = deleteDuplicates(head->next);
    //     if(head->val == head->next->val)
    //     {
    //         head = head->next;
    //     } 
    //     return head;
    // }

    ListNode* deleteDuplicates(ListNode* head) {
        if(head == NULL || head->next == NULL)
            return head;
        head->next = deleteDuplicates(head->next);
        if(head->val == head->next->val)
        {
            head = head->next;
        }
        return head;
    }



};
// @lc code=end

